Page({
  data:{ 
    orderList:[],
    orderid: ''
  },
  onLoad(){
  },
  onShow(){
    this.initData()
  },
  initData(){
    const orderList = wx.getStorageSync('movieOrder')
    if(orderList.length==0){
      wx.request({
        url: 'http://localhost:8080/movie/all',
        method:'GET',
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          'token':wx.getStorageSync('token')
         },
         success(res){
           console.log(res)
           var order=res.data.data
           wx.setStorageSync('movieOrder', order)
         }
      })
    }
    this.setData({
      orderList
    })
  },
  //删除订单
  deleteOrder(e){
    const index = e.currentTarget.dataset.index;
    console.log(index)
    let orderList = this.data.orderList.slice();
    console.log(orderList)
    orderList.splice(index,1)
    console.log(orderList)
    wx.showModal({
      title: '提示',
      content: '确认删除订单吗？',
      success:(res)=>{
        if(res.confirm){
          wx.request({
            url: 'http://localhost:8080/movie?orderId='+orderList[index].orderId,
            method: "DELETE",
            header: {
              'content-type': 'application/x-www-form-urlencoded',
              'token':wx.getStorageSync('token')
             },
            data:{
            
            },
            success(){
             
              wx.setStorageSync('movieOrder', orderList)
            }
          })
          this.setData({
            orderList
          })
        }
      }
    })
  },
  //跳转到订单详情页面
  goTo(e){
    const order = e.currentTarget.dataset.order
    const paramsStr = JSON.stringify(order)
    wx.navigateTo({
      url: `../movie-order-detail/movie-order-detail?paramsStr=${paramsStr}`
    })
  }
})